<?php

namespace ajiho\helper;

use think\Response;

class Api
{

    /**
     * api成功快速响应方法
     * @param mixed $data
     * @param string $msg
     * @param int $code
     * @return Response
     */
    public static function ok($data = [], string $msg = '', int $code = 200): Response
    {
        return Response::create(['code' => $code, 'msg' => $msg, 'data' => $data], 'json');
    }


    /**
     * api失败快速响应方法
     * @param string $msg
     * @param int $code
     * @param mixed $data
     * @return Response
     */
    public static function fail(string $msg, int $code = 500, $data = []): Response
    {
        return Response::create(['code' => $code, 'msg' => $msg, 'data' => $data], 'json');
    }
}